package com.gemme.gemme.home;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.viewpager.widget.ViewPager;

import com.alibaba.fastjson.JSON;
import com.gemme.gemme.BaseActivity;
import com.gemme.gemme.R;
import com.gemme.gemme.manager.DataManager;
import com.gemme.gemme.shequ.BrandFragment;
import com.gemme.gemme.shequ.BrandNewFragment;
import com.gemme.gemme.shequ.FmPagerAdapter;
import com.gemme.gemme.shequ.GuangchangFragment;
import com.gemme.gemme.shequ.GuanzhuFragment;
import com.gemme.gemme.shequ.Product2Fragment;
import com.gemme.gemme.shequ.ProductFragment;
import com.gemme.gemme.shequ.ProductNewFragment;
import com.google.android.material.tabs.TabLayout;
import com.jaeger.library.StatusBarUtil;
import com.yanzhenjie.recyclerview.SwipeRecyclerView;

import java.util.ArrayList;
import java.util.HashMap;



public class BrandActivity extends BaseActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_brand);
        initView();
        initTop();
    }


    private void initTop() {
        StatusBarUtil.setTransparent(this);
    }

    TabLayout tablayout;
    private ViewPager viewPager;
    private FmPagerAdapter pagerAdapter;
    private ArrayList<Fragment> fragments = new ArrayList<>();
    private String[] titles = new String[]{"品牌","产品"};
    private void initView() {
        View cancel = findViewById(R.id.cancel);
        EditText et_search = findViewById(R.id.et_search);
        //修改位置
       setFragment();
       ImageView back = findViewById(R.id.back);
       back.setOnClickListener(new View.OnClickListener() {
           @Override
           public void onClick(View view) {
               finish();
           }
       });

        tablayout = findViewById(R.id.tablayout);
        viewPager = (ViewPager)findViewById(R.id.viewpager);

        tablayout.addTab(tablayout.newTab());
        tablayout.addTab(tablayout.newTab());
        tablayout.setupWithViewPager(viewPager,false);
        pagerAdapter = new FmPagerAdapter(fragments,getSupportFragmentManager());
        viewPager.setAdapter(pagerAdapter);

        for(int i=0;i<titles.length;i++){
            tablayout.getTabAt(i).setText(titles[i]);
        }
        cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(mContext, ProductListActivity.class);
                intent.putExtra("keyWork",et_search.getText() + "");
                startActivity(intent);
            }
        });

    }

    private void setFragment() {
//        fragments.add(new BrandFragment());
        fragments.add(new BrandNewFragment());
        fragments.add(new ProductFragment());
//        fragments.add(new Product2Fragment());
    }

}